home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / hf / dsp / compand / tables.m < prev   
Encoding:
Text File  |  1994-07-28  |  5.8 KB  |  101 lines

  1. %  WARNING!!  For the expert MATLAB user only!  This only shows the way
  2. %  our calculations were made.  It is NOT a general case file for modifying
  3. %  the coefficients in the compander.
  4. %
  5. %  TABLES.M  generates the tables of coefficients for the COMPAND
  6. %  program that runs on TI's DSP Starter Kit TMS320C26 board, and puts those
  7. %  into the proper include files.
  8. clear; 
  9. %    SET UP YOUR FREQUENCIES HERE!
  10. fs = 10e3;      %10 KHz sampling rate.
  11. M = 100; 
  12. n = -(M/2)+1:1:M/2;
  13. %
  14. %  l*(f3-f2) must = fs or the lookup table will not be finite where l is an
  15. %     integer.
  16. %  In this case m is 8.
  17. f1 = 176;     %the low frequency for the low filter.
  18. f2 = 626;    %the high frequency for the low filter/low frequency for the
  19.         %high receive filter.        .
  20. f3 = 1251;    %the low frequency for the high transmitt filter.
  21. f4 = 2500;    %the high frequency for the high transmitt filter.
  22. f5 = f4-f3+f2;    %the high frequency for the high receive filter.
  23.  
  24. % Compute the exponential tables here.
  25. l = 0:fs./(f3-f2)-1;    % 16*625 = 10000
  26. %  Check the sign on this shift.
  27. expary = exp(i*2*pi*(f3-f2)*l/fs);
  28. exparyr = round(real(expary)*(2.^15-1));    %round these and scale them.
  29. exparyi = round(imag(expary)*(2.^15-1));    %round these and scale them.
  30.  
  31. %     COMPUTE THE FILTER COEFFICIENTS
  32.  
  33. % We will use a real filter since we don't need to shift the low frequency
  34. % part.
  35. hlow = fir1(M-1,[2*f1/fs,2*f2/fs],kaiser(M,3));
  36.  
  37. % This part generates the analytic signal as well as doing the filtering to
  38. % give the upper band for the transmit filter.
  39. hhight = (-i/pi)./n.*(exp((i*2*pi*f4/fs).*n) - exp((i*2*pi*f3/fs).*n));
  40. hhight(M/2) = (f4-f3)*2/fs;
  41. hhight= hhight .* kaiser(M,3)'; %  Window it with a Kaiser window. 
  42.  
  43. % This part generates the analytic signal as well as doing the filtering to 
  44. % give the upper band for the receive filter.
  45. hhighr = (-i/pi)./n.*(exp((i*2*pi*f5/fs).*n) - exp((i*2*pi*f2/fs).*n));
  46. hhighr(M/2) = (f5-f2)*2/fs;
  47. hhighr= hhighr .* kaiser(M,3)'; %  Window it with a Kaiser window. 
  48.  
  49. % This part rounds the numbers and scales them up by 2^16.
  50. hlow = round(real(hlow/max(hlow).*(2.^14-1)));
  51. hhighrt = round(real(hhight)./max(abs(hhight)).*(2.^14-1));
  52. hhighit = round(imag(hhight)./max(abs(hhight)).*(2.^14-1));
  53. hhighrr = round(real(hhighr)./max(abs(hhighr)).*(2.^14-1));
  54. hhighir = round(imag(hhighr)./max(abs(hhighr)).*(2.^14-1));
  55.  
  56. % This section computes the frequency response curves.
  57. f = -fs/2:8:fs/2;    % This is the frequency axis variable for the plots.
  58. H = zeros(size(f));    % H is the frequency curve for the low filter.
  59. for m = -(M/2)+1:1:M/2;
  60.     H = H + hlow(m+M/2)*exp((-i*2*pi/fs*m).*f);
  61. end
  62. H2r = zeros(size(f));    % H2r is the frequency curve for the high receive filt.
  63. for m = -(M/2)+1:1:M/2;
  64.     H2r = H2r + (hhighrr(m+M/2)+i*hhighir(m+M/2))*exp((-i*2*pi/fs*m).*f);
  65. end
  66. H2t= zeros(size(f));    % H2t is the frequency curve for the high receive filt.
  67. for m = -(M/2)+1:1:M/2;
  68.     H2t = H2t + (hhighrt(m+M/2)+i*hhighit(m+M/2))*exp((-i*2*pi/fs*m).*f);
  69. end
  70.  
  71. %  We want the same passband heights on all filters so we make it so here!
  72. hlow = round(hlow/max(abs(H))*max(abs(H2t)));
  73.  
  74. %  Redo the low filter frequency response to see that it has been scaled
  75. %  correctly.
  76. H = zeros(size(f));    % H is the frequency curve for the low filter.
  77. for m = -(M/2)+1:1:M/2;
  78.     H = H + hlow(m+M/2)*exp((-i*2*pi/fs*m).*f);
  79. end
  80.  
  81.  
  82. %  Plot the frequency response curves.
  83. plot(f,20*log(abs(H)),f,20*log(abs(H2r)),f,20*log(abs(H2t)));
  84.  
  85. %     WRITE out the files here.
  86. %    Write the low filter file.
  87. fid = fopen('COEF.ASM','w');
  88. fprintf(fid,'COEF1_R .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n',hlow);
  89. %    Write the transmitt files.
  90. fprintf(fid,'COEF2R_T .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n',hhighrt);
  91. fprintf(fid,'COEF2T_I .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n',hhighit);
  92.  
  93. %    Write the receive files.
  94. fprintf(fid,'COEF2R_R .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n',hhighrr);
  95. fprintf(fid,'COEF2R_I .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n',hhighir);
  96.  
  97. %    Write the exponential file.
  98. fidexp = fopen('EXP.ASM','w');
  99. fprintf(fidexp,'EXP_R .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n',exparyr);
  100. fprintf(fidexp,'EXP_I .word %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n',exparyi);
  101.